package com.elicitor.listner;

import com.elicitor.core.Alogrithm;
import com.elicitor.core.NeuralNetworkFiveInput;
import com.elicitor.core.PraatCall;
import com.elicitor.svm.SVMPredict;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

public class Elicitorgui extends JFrame {

    String datafile;
    private JTextArea neuralTextArea;

    /**
     * This GUI is created for compact the functionalities of Elicitor.
     */
    public Elicitorgui() {

        initComponents();

        endCapturing.setEnabled(false);  //Disable the stop capture button
        extractEmotionPraat.setEnabled(false);   //Disable attribute extract button until capture the voice clip
        attributeAnalysis.setEnabled(false);      // disable the analyze button until extract the emotions        

        analyzeButtonSVM.setEnabled(false); // SVM analyze button should get enabled when the file get selected.

    }
    MicRecorder mr;
    String fileLocation;

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        startCapturing = new javax.swing.JButton();
        endCapturing = new javax.swing.JButton();
        extractEmotionPraat = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        attributeAnalysis = new javax.swing.JButton();
        emotionLabel = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        encogAnalyzer = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        neuralTextArea = new javax.swing.JTextArea();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        SVMTexrArea = new javax.swing.JTextArea();
        jPanel7 = new javax.swing.JPanel();
        SVMFilePath = new javax.swing.JTextField();
        browseButtonSVM = new javax.swing.JButton();
        analyzeButtonSVM = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        startCapturing.setText("Start Capturing");
        startCapturing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startCapturingActionPerformed(evt);
            }
        });

        endCapturing.setText("End Capturing");
        endCapturing.setRequestFocusEnabled(false);
        endCapturing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                endCapturingActionPerformed(evt);
            }
        });

        extractEmotionPraat.setText("Extract Attributes");
        extractEmotionPraat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                extractEmotionPraatActionPerformed(evt);
            }
        });

        jLabel1.setBackground(new java.awt.Color(240, 241, 242));
        jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 60)); // NOI18N
        jLabel1.setText("ELICITOR");

        attributeAnalysis.setText("Analyze");
        attributeAnalysis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                attributeAnalysisActionPerformed(evt);
            }
        });

        emotionLabel.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        emotionLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        emotionLabel.setText("jLabel2");
        emotionLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel3.setText("2012");

        jTabbedPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 700, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 334, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Elicitor", jPanel1);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 696, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 330, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Information", jPanel2);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 700, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 334, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Parameter Values", jPanel3);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 700, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 334, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Clusttering", jPanel4);

        encogAnalyzer.setText("Encog Analyzer");
        encogAnalyzer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                encogAnalyzerActionPerformed(evt);
            }
        });

        jButton3.setText("NeuralNetworkWith24");

        jButton4.setText("NeuralNetworkWith5");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        neuralTextArea.setColumns(20);
        neuralTextArea.setRows(5);
        jScrollPane2.setViewportView(neuralTextArea);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addComponent(encogAnalyzer, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(58, 58, 58)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(49, 49, 49)
                        .addComponent(jButton4))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 429, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(101, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(encogAnalyzer)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap(258, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Neural Network", jPanel5);

        SVMTexrArea.setColumns(20);
        SVMTexrArea.setRows(5);
        jScrollPane1.setViewportView(SVMTexrArea);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Predict the emotion from a saved file"));
        jPanel7.setName("Predict"); // NOI18N

        browseButtonSVM.setText("Browse");
        browseButtonSVM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButtonSVMActionPerformed(evt);
            }
        });

        analyzeButtonSVM.setText("Analyze");
        analyzeButtonSVM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                analyzeButtonSVMActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(SVMFilePath, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
                .addGap(10, 10, 10)
                .addComponent(browseButtonSVM)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(analyzeButtonSVM)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SVMFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(browseButtonSVM)
                    .addComponent(analyzeButtonSVM))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane1)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(45, 45, 45))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(38, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24))
        );

        jTabbedPane1.addTab("SVM", jPanel6);

        jButton1.setText("Clear");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Exit");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 709, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(startCapturing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(endCapturing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(extractEmotionPraat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(attributeAnalysis, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 350, Short.MAX_VALUE)
                        .addComponent(emotionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(24, 24, 24))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(emotionLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(startCapturing)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(endCapturing)
                        .addGap(37, 37, 37)
                        .addComponent(extractEmotionPraat)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(attributeAnalysis)
                        .addGap(98, 98, 98)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)
                        .addGap(73, 73, 73))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(67, Short.MAX_VALUE))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void startCapturingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startCapturingActionPerformed

    mr = new MicRecorder(new AudioFormat(22000, 16, 2, true, true));
    mr.start();
    endCapturing.setEnabled(true);

}//GEN-LAST:event_startCapturingActionPerformed

private void endCapturingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_endCapturingActionPerformed

    extractEmotionPraat.setEnabled(true);
    mr.stop();
    WaveData wd = new WaveData();
    try {
        Thread.sleep(3000);
    } catch (InterruptedException ex) {
        Logger.getLogger(Elicitorgui.class.getName()).log(Level.SEVERE, null, ex);
    }
    fileLocation = wd.saveToFile("clip0", AudioFileFormat.Type.WAVE, mr.getAudioInputStream());
}//GEN-LAST:event_endCapturingActionPerformed

private void extractEmotionPraatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_extractEmotionPraatActionPerformed

    startCapturing.setEnabled(false);
    endCapturing.setEnabled(false);
    PraatCall prattcall = new PraatCall(fileLocation);
    prattcall.createNewVoiceFile();
    prattcall.sendPraat();
    attributeAnalysis.setEnabled(true);

}//GEN-LAST:event_extractEmotionPraatActionPerformed

private void attributeAnalysisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_attributeAnalysisActionPerformed

    Alogrithm algo = new Alogrithm("info.txt");
    String suitableEmotion = algo.detectEmotion();

    /*  
     *  Support vector machine implementation
     *  This code can be extended to use any number of parameters / attributes
     *  Attributes should be in the first file (ie: info.txt) and they should be comma seperated. 
     *  ie : 3.200002321, 3.423212, 1234.23231
     * 
     *  Code has to be extended to post analysis of the results with the fuctionality 
     *  to select the file and button to proceed with the prediction.
     *  
     */

    try {
        int emotion = (int) SVMPredict.Analyze("info.txt", "svm_resources/test.txt.model", "x.out");
        System.out.println(Emotions.getEmotion(emotion));
        getSVMData(emotion);
    } catch (IOException ex) {
        Logger.getLogger(Elicitorgui.class.getName()).log(Level.SEVERE, null, ex);
    }

    emotionLabel.setText(suitableEmotion);
    emotionLabel.setVisible(true);
}//GEN-LAST:event_attributeAnalysisActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int x = JOptionPane.showConfirmDialog(this, "Do you want to close Elicitor", "Close Elicitor", 0);
        if (x == 0) {
            System.exit(0);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        startCapturing.setEnabled(true);
        endCapturing.setEnabled(false);  //Disable the stop capture button
        extractEmotionPraat.setEnabled(false);   //Disable attribute extract button until capture the voice clip
        attributeAnalysis.setEnabled(false);      // disable the analyze button until extract the emotions
        analyzeButtonSVM.setEnabled(false);
    }//GEN-LAST:event_jButton1ActionPerformed

private void encogAnalyzerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_encogAnalyzerActionPerformed

    Runtime run = Runtime.getRuntime();
    try {
        String[] sendpraatCom = new String[3];
        sendpraatCom[0] = "java";
        sendpraatCom[1] = "-jar";
        sendpraatCom[2] = "EncogWorkbenchStartable-2.5.3.jar";
        run.exec(sendpraatCom);
    } catch (Exception ex) {
        System.err.println("Error... " + ex.getMessage());
    }



}//GEN-LAST:event_encogAnalyzerActionPerformed

    private void analyzeButtonSVMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_analyzeButtonSVMActionPerformed
        /*
         * wenod pathirana
         * This method is to analyze saved attributes of a voice clip..
         * 
         */
        try {
            int emotion = (int) SVMPredict.Analyze(datafile, "svm_resources/test.txt.model", "x.out");
            System.out.println(Emotions.getEmotion(emotion));
            getSVMData(emotion);
        } catch (IOException ex) {
            Logger.getLogger(Elicitorgui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_analyzeButtonSVMActionPerformed

    private void getSVMData(int emotion) throws IOException {


//        BufferedReader input = new BufferedReader(new FileReader("svm_resources\\test.txt.model"));
        StringBuilder builder = new StringBuilder();
        builder.append("\n" + "Suport Vector Machine : C-SVC"
                + "\n" + "Kernel function : Polynimial (degree --> 2)"
                //+ "\n" + input.readLine()
                + "\n" + Emotions.getEmotion(emotion).toString());

        SVMTexrArea.setText(builder.toString());
    }

    private void browseButtonSVMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonSVMActionPerformed

        /*
         * wenod pathirana
         * open file dialog box
         */

        JFileChooser chooser = new JFileChooser();
        int returnVal = chooser.showOpenDialog(this);

        System.out.println(returnVal);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            datafile = file.getName();
            //This is where a real application would open the file.
            //log.append("Opening: " + file.getName() + "." + newline);
            SVMFilePath.setText(file.getPath());
            analyzeButtonSVM.setEnabled(true);
        } else {
            //log.append("Open command cancelled by user." + newline);
        }
    }//GEN-LAST:event_browseButtonSVMActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed

    NeuralNetworkFiveInput neuralData = new NeuralNetworkFiveInput("info.txt");
    Double []result = neuralData.getEmotions();
        neuralTextArea.setText("Anger  "+result[0].toString()+"%"+"\nDisgust  "+result[1].toString()+"%"+"\nFear  "+result[2].toString()+"%"+"\nHappy  "+result[3].toString()+"%"+"\nSadness  "+result[4].toString()+"%"+"\nSurprise  "+result[5].toString()+"%");

}//GEN-LAST:event_jButton4ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Elicitorgui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Elicitorgui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Elicitorgui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Elicitorgui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Elicitorgui().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField SVMFilePath;
    private javax.swing.JTextArea SVMTexrArea;
    private javax.swing.JButton analyzeButtonSVM;
    private javax.swing.JButton attributeAnalysis;
    private javax.swing.JButton browseButtonSVM;
    private javax.swing.JLabel emotionLabel;
    private javax.swing.JButton encogAnalyzer;
    private javax.swing.JButton endCapturing;
    private javax.swing.JButton extractEmotionPraat;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton startCapturing;
    // End of variables declaration//GEN-END:variables
}
